package com.xoa.controller.attendance.attendanceSetting;

import com.xoa.model.attendance.AttendScheduleWithBLOBs;
import com.xoa.service.attendance.schedule.AttendScheduleService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
/**
* @创建作者:李然  Lr
* @方法描述：排班管理
* @创建时间：15:59 2018/9/20
**/
@RequestMapping("attendSchedule")
public class AttendScheduleController {

    @Autowired
    private AttendScheduleService attendScheduleService;

    /**
     * 获取排班管理主页数据
     */
    @ResponseBody
    @RequestMapping(value = "/getAttendSchedule")
    public ToJson getAttendSchedule(){
        return attendScheduleService.getAttendSchedule();
    }

    /**
     * 新增排班
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insertSchedule")
    public ToJson insertSchedule(AttendScheduleWithBLOBs attendScheduleWithBLOBs){
        return attendScheduleService.insertAttendSchedule(attendScheduleWithBLOBs);
    }

    /**
     * 获取编辑数据
     */
    @ResponseBody
    @RequestMapping(value = "/getAttendScheduleById")
    public ToJson getAttendScheduleById(Integer asid){
        return attendScheduleService.getAttendScheduleById(asid);
    }

    /**
     * 编辑
     */
    @ResponseBody
    @RequestMapping(value = "/updateAttendSchedule")
    public ToJson updateAttendSchedule(AttendScheduleWithBLOBs attendScheduleWithBLOBs){
        return attendScheduleService.updateAttendSchedule(attendScheduleWithBLOBs);
    }
    /**
     * 停用，启用
     */
    @ResponseBody
    @RequestMapping(value = "/updateAttendScheduleStatus")
    public ToJson updateAttendScheduleStatus(Integer asid ){
        return attendScheduleService.updateAttendScheduleStatus(asid);
    }
    /**
     * 删除
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteAttendSchedule")
    public ToJson deleteAttendSchedule(Integer asid ){
        return  attendScheduleService.deleteAttendSchedule(asid);
    }

    /**
     * 自由排班查询
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/freedomScheduleQuery")
    public ToJson freedomScheduleQuery(
            @RequestParam(required = false,value = "deptIds") String deptIds,
            @RequestParam(required = false,value = "userIds") String userIds,
            @RequestParam(required = false,value = "date") String date,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) Integer page,
            @RequestParam(required = false) Boolean useFlag){
        return attendScheduleService.freedomScheduleQuery(deptIds,userIds,date,pageSize,page,useFlag);
    }

    /**
     * 自由排班保存
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/freedomScheduleSave")
    public ToJson freedomScheduleSave(@RequestParam(required = false,value = "userDutyList[]")List<String> userDutyList){
        return attendScheduleService.freedomScheduleSave(userDutyList);
    }

    /**
     * 保存排班调度（优先级最大）
     */
    @ResponseBody
    @RequestMapping(value = "/saveUserDuty")
    public ToJson saveUserDuty(AttendScheduleWithBLOBs attendScheduleWithBLOBs){
        return attendScheduleService.saveUserDuty(attendScheduleWithBLOBs);
    }

    /**
     * 显示所有排班的类型
     */
    @ResponseBody
    @RequestMapping(value = "/getAttendSet")
    public ToJson getAttendSet(){
        return attendScheduleService.getAttendSet();
    }
}
